#include "RenderableDroplet.h"

RenderableDroplet::RenderableDroplet() : RenderableObject() { return; }

RenderableDroplet::RenderableDroplet(
	OGLDataObject *objectData, 
	OGLGeometryData *geometryData
	) : RenderableObject(objectData, geometryData) { return; }

RenderableDroplet::~RenderableDroplet() { return; }
	
OGLResult RenderableDroplet::UpdateColor(float r, float g, float b, float a)
{
	// TODO : Optimization - map buffer only if color value different from previous value 

	GLenum errorCheckValue = glGetError();

	glBindBuffer(objData->dataType, objData->GetVBOID());
	float *vData = (float *)glMapBufferRange(
		objData->dataType, 
		sizeof(vertexData[0].XYZW), 
		sizeof(vertexData[0].RGBA), 
		GL_MAP_WRITE_BIT);
	if(vData == NULL)
	{
		errorCheckValue = glGetError();
		fprintf(
			stderr,
			"[WARNING] Could not map buffer range : %s \n",
			gluErrorString(errorCheckValue)
		);

		return OGL_WARNING;
	}
	else
	{
		// R, G, B, A values in entries 0 - 3
		vData[0] = r;
		vData[1] = g;
		vData[2] = b;
		vData[3] = a;

		glUnmapBuffer(GL_ARRAY_BUFFER);
	}

	return OGL_SUCCESS;
}